<%--
  Created by IntelliJ IDEA.
  User: 石小俊
  Date: 2024/11/23
  Time: 15:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>文件上传</title>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.4.1.min.js"></script>
    <script>
        $(function(){
            $("#btn").click(function(){
                let formData = new FormData($("#uploadForm")[0]);
                $.ajax({
                    type: "post",
                    url:"${pageContext.request.contextPath}/upload",
                    data:formData,
                    processData: false,
                    contentType: false,
                    success:function(result){
                        $("#s1").html(result)
                    }
                })
            });
        })
    </script>
</head>
<body>
<h1>文件上传</h1>
<hr>
<form id="uploadForm">
    用户名:<input type="text" name="username"><br>
    文件:<input type="file" name="file"><br>
    <input type="button" id="btn" value="提交">
    <span id="s1"></span>
</form>
</body>
</html>
